<!DOCTYPE html><html lang="zh-CN" data-theme="light"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no"><title>JavaScript 第二天 | XC's Blog</title><meta name="keywords" content="JavaScript笔记"><meta name="author" content="XC's Blog"><meta name="copyright" content="XC's Blog"><meta name="format-detection" content="telephone=no"><meta name="theme-color" content="#ffffff"><meta name="description" content="JavaScript 基础第二天算术运算符: 经常作为某个数字是否被整除 数学运算也叫算术运算, 主要包括加、减、乘、除、取余(取模) +：求和、-：求差、*：求积、&#x2F;：求商、%：取余    算术运算符优先级顺序: 同时使用多个运算符写程序时, 会按某种顺序先后执行, 称为优先级  js中, 优先级越高越先被执行, 优先级相同时左向右执  乘、除、取余优先级相同, 加、减优先级相同  乘"><meta property="og:type" content="article"><meta property="og:title" content="JavaScript 第二天"><meta property="og:url" content="https://webxc.eu.org/post/623e/index.html"><meta property="og:site_name" content="XC&#39;s Blog"><meta property="og:description" content="JavaScript 基础第二天算术运算符: 经常作为某个数字是否被整除 数学运算也叫算术运算, 主要包括加、减、乘、除、取余(取模) +：求和、-：求差、*：求积、&#x2F;：求商、%：取余    算术运算符优先级顺序: 同时使用多个运算符写程序时, 会按某种顺序先后执行, 称为优先级  js中, 优先级越高越先被执行, 优先级相同时左向右执  乘、除、取余优先级相同, 加、减优先级相同  乘"><meta property="og:locale" content="zh_CN"><meta property="og:image" content="https://npm.elemecdn.com/webxc/cover/js1.webp"><meta property="article:published_time" content="2022-12-05T17:00:00.000Z"><meta property="article:modified_time" content="2023-08-30T18:00:49.037Z"><meta property="article:author" content="XC&#39;s Blog"><meta property="article:tag" content="JavaScript笔记"><meta name="twitter:card" content="summary"><meta name="twitter:image" content="https://npm.elemecdn.com/webxc/cover/js1.webp"><link rel="shortcut icon" href="https://npm.elemecdn.com/webxc@1.0.0/logo/logo.jpg"><link rel="canonical" href="https://webxc.eu.org/post/623e/"><link rel="preconnect" href="//cdn.jsdelivr.net"><link rel="preconnect" href="//busuanzi.ibruce.info"><link rel="stylesheet" href="/css/index.css"><link rel="stylesheet" href="https://npm.elemecdn.com/@fortawesome/fontawesome-free@6.2.0/css/all.min.css" media="print" onload='this.media="all"'><link rel="stylesheet" href="https://npm.elemecdn.com/node-snackbar/dist/snackbar.min.css" media="print" onload='this.media="all"'><link rel="stylesheet" href="https://npm.elemecdn.com/@fancyapps/ui/dist/fancybox.css" media="print" onload='this.media="all"'><script>const GLOBAL_CONFIG={root:"/",algolia:void 0,localSearch:{path:"/search.xml",preload:!1,languages:{hits_empty:"找不到您查询的内容：${query}"}},translate:void 0,noticeOutdate:void 0,highlight:{plugin:"highlighjs",highlightCopy:!0,highlightLang:!0,highlightHeightLimit:!1},copy:{success:"吾辈宣布,你的剪切板已被占领",error:"呀~复制失败,请在尝试下",noSupport:"对不起,你的浏览器不支持"},relativeDate:{homepage:!1,post:!1},runtime:"",date_suffix:{just:"刚刚",min:"分钟前",hour:"小时前",day:"天前",month:"个月前"},copyright:{limitCount:60,languages:{author:"作者: XC's Blog",link:"链接: ",source:"来源: XC's Blog",info:"著作权归作者所有。商业转载请联系作者获得授权，非商业转载请注明出处。"}},lightbox:"fancybox",Snackbar:{chs_to_cht:"您已切换为繁体",cht_to_chs:"您已切换为简体",day_to_night:"您已切换为深色主题",night_to_day:"您已切换为浅色主题",bgLight:"#3b70fc",bgDark:"#121212",position:"bottom-center"},source:{justifiedGallery:{js:"https://npm.elemecdn.com/flickr-justified-gallery/dist/fjGallery.min.js",css:"https://npm.elemecdn.com/flickr-justified-gallery/dist/fjGallery.css"}},isPhotoFigcaption:!1,islazyload:!0,isAnchor:!0}</script><script id="config-diff">var GLOBAL_CONFIG_SITE={title:"JavaScript 第二天",isPost:!0,isHome:!1,isHighlightShrink:!1,isToc:!0,postUpdate:"2023-08-30 18:00:49"}</script><noscript><style>#nav{opacity:1}.justified-gallery img{opacity:1}#post-meta time,#recent-posts time{display:inline!important}</style></noscript><script>(e=>{e.saveToLocal={set:function(e,t,o){if(0===o)return;const n=864e5*o,a={value:t,expiry:(new Date).getTime()+n};localStorage.setItem(e,JSON.stringify(a))},get:function(e){const t=localStorage.getItem(e);if(!t)return;const o=JSON.parse(t);if(!((new Date).getTime()>o.expiry))return o.value;localStorage.removeItem(e)}},e.getScript=e=>new Promise(((t,o)=>{const n=document.createElement("script");n.src=e,n.async=!0,n.onerror=o,n.onload=n.onreadystatechange=function(){const e=this.readyState;e&&"loaded"!==e&&"complete"!==e||(n.onload=n.onreadystatechange=null,t())},document.head.appendChild(n)})),e.activateDarkMode=function(){document.documentElement.setAttribute("data-theme","dark"),null!==document.querySelector('meta[name="theme-color"]')&&document.querySelector('meta[name="theme-color"]').setAttribute("content","#0d0d0d")},e.activateLightMode=function(){document.documentElement.setAttribute("data-theme","light"),null!==document.querySelector('meta[name="theme-color"]')&&document.querySelector('meta[name="theme-color"]').setAttribute("content","#ffffff")};const t=saveToLocal.get("theme");"dark"===t?activateDarkMode():"light"===t&&activateLightMode();const o=saveToLocal.get("aside-status");void 0!==o&&("hide"===o?document.documentElement.classList.add("hide-aside"):document.documentElement.classList.remove("hide-aside"));/iPad|iPhone|iPod|Macintosh/.test(navigator.userAgent)&&document.documentElement.classList.add("apple")})(window)</script><link rel="stylesheet" href="https://cdn1.tianli0.top/gh/web-xc/My-blog-CSS/mgi.css"><link rel="stylesheet" href="https://cdn1.tianli0.top/gh/web-xc/My-blog-CSS/mg111.css"><link rel="stylesheet" href="https://npm.elemecdn.com/webxc@1.0.16/css/mg2.css"><link rel="stylesheet" href="https://npm.elemecdn.com/webxc@1.0.11/css/styless.css"><link rel="stylesheet" href="https://npm.elemecdn.com/webxc@1.0.11/css/styles.css"><link rel="stylesheet" href="https://npm.elemecdn.com/webxc@1.0.11/css/font.css"><link rel="stylesheet" href="https://npm.elemecdn.com/webxc@1.0.15/css/font2.css"><link rel="stylesheet" href="https://npm.elemecdn.com/webxc@1.0.12/css/swiper/swiper.min.css" media="print" onload='this.media="all"'><link rel="stylesheet" href="https://npm.elemecdn.com/webxc@1.0.12/css/swiper/swiperstyle.css" media="print" onload='this.media="all"'><meta name="generator" content="Hexo 6.3.0"></head><body><div id="sidebar"><div id="menu-mask"></div><div id="sidebar-menus"><div class="avatar-img is-center"><img src="https://npm.elemecdn.com/webxc@1.0.0/logo/logo.jpg" onerror='onerror=null,src="https://npm.elemecdn.com/webxc@1.0.2/banner/404.gif"' alt="avatar"></div><div class="sidebar-site-data site-data is-center"><a href="/archives/"><div class="headline">文章</div><div class="length-num">95</div></a><a href="/tags/"><div class="headline">标签</div><div class="length-num">25</div></a><a href="/categories/"><div class="headline">分类</div><div class="length-num">25</div></a></div><hr><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw iconfont icon-shouye"></i> <span>首页</span></a></div><div class="menus_item"><a class="site-page" href="/archives/"><i class="fa-fw iconfont icon-shijian"></i> <span>时间轴</span></a></div><div class="menus_item"><a class="site-page" href="/tags/"><i class="fa-fw iconfont icon-biaoqian"></i> <span>标签</span></a></div><div class="menus_item"><a class="site-page" href="/categories/"><i class="fa-fw iconfont icon-fenlei"></i> <span>分类</span></a></div><div class="menus_item"><a class="site-page" href="/link/"><i class="fa-fw iconfont icon-lianxiwomen"></i> <span>友联</span></a></div><div class="menus_item"><a class="site-page" href="/about/"><i class="fa-fw iconfont icon-iconzhengli-"></i> <span>关于</span></a></div><div class="menus_item"><a class="site-page group hide" href="javascript:void(0);"><i class="fa-fw iconfont icon-a-wangzhanchaojilianjiehulianwang"></i> <span>推荐</span><i class="fas fa-chevron-down"></i></a><ul class="menus_item_child"><li><a class="site-page child" target="_blank" rel="noopener" href="http://www.inode.club/"><i class="fa-fw fa-sharp fa-solid fa-square-rss"></i> <span>程序员指南</span></a></li><li><a class="site-page child" target="_blank" rel="noopener" href="http://ife.baidu.com/"><i class="fa-fw fa-brands fa-vuejs"></i> <span>前端技术学园</span></a></li><li><a class="site-page child" target="_blank" rel="noopener" href="https://www.yuque.com/tademanong/ag7q4n"><i class="fa-fw fa-solid fa-users"></i> <span>前端技术圈</span></a></li><li><a class="site-page child" target="_blank" rel="noopener" href="https://www.code-nav.cn/"><i class="fa-fw fa-solid fa-shop"></i> <span>编程导航</span></a></li><li><a class="site-page child" target="_blank" rel="noopener" href="https://q.shanyue.tech/"><i class="fa-fw fa-brands fa-square-js"></i> <span>每日一题</span></a></li><li><a class="site-page child" target="_blank" rel="noopener" href="https://fanyouf.gitee.io/u1word/#/h5"><i class="fa-fw fa-solid fa-headphones"></i> <span>前端必会单词</span></a></li><li><a class="site-page child" target="_blank" rel="noopener" href="https://site.51git.cn/render/gonav/4.html"><i class="fa-fw iconfont icon-wangzhandingzhi"></i> <span>网址导航</span></a></li><li><a class="site-page child" target="_blank" rel="noopener" href="https://www.webxc.eu.org/music/"><i class="fa-fw iconfont icon-musical-note"></i> <span>音乐解锁</span></a></li></ul></div></div></div></div><div class="post" id="body-wrap"><header class="post-bg" id="page-header" style="background-image:url('https://npm.elemecdn.com/webxc/cover/js1.webp')"><nav id="nav"><span id="blog_name"><div class="back-home-button" tabindex="-1"><i class="back-home-button-icon fas fa-grip-vertical"></i><div class="back-menu-list-groups"><div class="back-menu-list-group"><div class="back-menu-list-title">项目</div><div class="back-menu-list"><a class="back-menu-item" href="/" title="前往博客主页" target="_blank" one-link-mark="yes"><img class="back-menu-item-icon" src="https://npm.elemecdn.com/webxc@1.0.0/logo/logo.jpg"><span class="back-menu-item-text">主站</span></a><a class="back-menu-item" href="https://e.webxc.eu.org/" rel="external nofollow" title="前往学习笔记" target="_blank" one-link-mark="yes"><img class="back-menu-item-icon" src="https://npm.elemecdn.com/webxc@1.0.0/logo/logo.jpg"><span class="back-menu-item-text">学习笔记</span></a><a class="back-menu-item" href="https://v.webxc.eu.org/" rel="external nofollow" title="VuePress学习文档" target="_blank" one-link-mark="yes"><img class="back-menu-item-icon" src="https://npm.elemecdn.com/webxc@1.0.0/logo/logo.jpg"><span class="back-menu-item-text">VuePress文档</span></a><a class="back-menu-item" href="https://b.webxc.eu.org/" rel="external nofollow" title="旧站Hexo" target="_blank" one-link-mark="yes"><img class="back-menu-item-icon" src="https://npm.elemecdn.com/webxc@1.0.0/logo/logo.jpg"><span class="back-menu-item-text">旧站Hexo</span></a><a class="back-menu-item" href="https://gridea.webxc.eu.org/" rel="external nofollow" title="Gridea笔记" target="_blank" one-link-mark="yes"><img class="back-menu-item-icon" src="https://npm.elemecdn.com/webxc@1.0.0/logo/logo.jpg"><span class="back-menu-item-text">Gridea笔记</span></a><a class="back-menu-item" href="https://c.webxc.eu.org/" rel="external nofollow" title="魔改Hexo" target="_blank" one-link-mark="yes"><img class="back-menu-item-icon" src="https://npm.elemecdn.com/webxc@1.0.0/logo/logo.jpg"><span class="back-menu-item-text">魔改Hexo</span></a></div></div><div class="back-menu-list-group"><div class="back-menu-list-title">博客镜像</div><div class="back-menu-list"><a class="back-menu-item" href="https://blog.webxc.eu.org/" title="Vercel镜像" target="_blank" rel="noopener nofollow" one-link-mark="yes"><img class="back-menu-item-icon" src="https://npm.elemecdn.com/webxc@1.0.0/logo/logo.jpg"><span class="back-menu-item-text">Vercel镜像</span></a><a class="back-menu-item" href="https://webxc.tk/" title="Netlify镜像" target="_blank" rel="noopener nofollow" one-link-mark="yes"><img class="back-menu-item-icon" src="https://npm.elemecdn.com/webxc@1.0.0/logo/logo.jpg"><span class="back-menu-item-text">Netlify镜像</span></a><a class="back-menu-item" href="https://web-xc.gitee.io/" title="Gitee镜像" target="_blank" rel="noopener nofollow" one-link-mark="yes"><img class="back-menu-item-icon" src="https://npm.elemecdn.com/webxc@1.0.0/logo/logo.jpg"><span class="back-menu-item-text">Gitee镜像</span></a><a class="back-menu-item" href="https://cf.webxc.eu.org/" title="Cloudflare镜像" target="_blank" rel="noopener nofollow" one-link-mark="yes"><img class="back-menu-item-icon" src="https://npm.elemecdn.com/webxc@1.0.0/logo/logo.jpg"><span class="back-menu-item-text">Cloudflare镜像</span></a><a class="back-menu-item" href="https://render.webxc.eu.org/" title="Render镜像" target="_blank" rel="noopener nofollow" one-link-mark="yes"><img class="back-menu-item-icon" src="https://npm.elemecdn.com/webxc@1.0.0/logo/logo.jpg"><span class="back-menu-item-text">Render镜像</span></a></div></div></div></div><a id="site-name" href="/"><div class="title">XC's Blog</div><i class="fa-solid fa-house"></i></a></span><div class="mask-name-container"><center id="name-container"><a id="page-name" href="javascript:btf.scrollToDest(0, 500)">PAGE_NAME</a></center></div><div id="menus"><div class="nav-button" id="search-button"><a class="site-page social-icon search"><i class="fas fa-search fa-fw"></i> <span>搜索</span></a></div><div class="nav-button" id="darkmode_navswitch"><a class="darkmode_switchbutton" type="button" title="浅色和深色模式转换" onclick="switchDarkMode()"><i class="fas fa-adjust"></i></a></div><div class="nav-button" id="nav-totop"><a class="totopbtn"><i class="fas fa-arrow-up"></i><span id="percent" onclick="btf.scrollToDest(0,500)">0</span></a></div><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw iconfont icon-shouye"></i> <span>首页</span></a></div><div class="menus_item"><a class="site-page" href="/archives/"><i class="fa-fw iconfont icon-shijian"></i> <span>时间轴</span></a></div><div class="menus_item"><a class="site-page" href="/tags/"><i class="fa-fw iconfont icon-biaoqian"></i> <span>标签</span></a></div><div class="menus_item"><a class="site-page" href="/categories/"><i class="fa-fw iconfont icon-fenlei"></i> <span>分类</span></a></div><div class="menus_item"><a class="site-page" href="/link/"><i class="fa-fw iconfont icon-lianxiwomen"></i> <span>友联</span></a></div><div class="menus_item"><a class="site-page" href="/about/"><i class="fa-fw iconfont icon-iconzhengli-"></i> <span>关于</span></a></div><div class="menus_item"><a class="site-page group hide" href="javascript:void(0);"><i class="fa-fw iconfont icon-a-wangzhanchaojilianjiehulianwang"></i> <span>推荐</span><i class="fas fa-chevron-down"></i></a><ul class="menus_item_child"><li><a class="site-page child" target="_blank" rel="noopener" href="http://www.inode.club/"><i class="fa-fw fa-sharp fa-solid fa-square-rss"></i> <span>程序员指南</span></a></li><li><a class="site-page child" target="_blank" rel="noopener" href="http://ife.baidu.com/"><i class="fa-fw fa-brands fa-vuejs"></i> <span>前端技术学园</span></a></li><li><a class="site-page child" target="_blank" rel="noopener" href="https://www.yuque.com/tademanong/ag7q4n"><i class="fa-fw fa-solid fa-users"></i> <span>前端技术圈</span></a></li><li><a class="site-page child" target="_blank" rel="noopener" href="https://www.code-nav.cn/"><i class="fa-fw fa-solid fa-shop"></i> <span>编程导航</span></a></li><li><a class="site-page child" target="_blank" rel="noopener" href="https://q.shanyue.tech/"><i class="fa-fw fa-brands fa-square-js"></i> <span>每日一题</span></a></li><li><a class="site-page child" target="_blank" rel="noopener" href="https://fanyouf.gitee.io/u1word/#/h5"><i class="fa-fw fa-solid fa-headphones"></i> <span>前端必会单词</span></a></li><li><a class="site-page child" target="_blank" rel="noopener" href="https://site.51git.cn/render/gonav/4.html"><i class="fa-fw iconfont icon-wangzhandingzhi"></i> <span>网址导航</span></a></li><li><a class="site-page child" target="_blank" rel="noopener" href="https://www.webxc.eu.org/music/"><i class="fa-fw iconfont icon-musical-note"></i> <span>音乐解锁</span></a></li></ul></div></div><div id="toggle-menu"><a class="site-page"><i class="fas fa-bars fa-fw"></i></a></div></div></nav><div id="post-info"><h1 class="post-title">JavaScript 第二天</h1><div id="post-meta"><div class="meta-firstline"><span class="post-meta-date"><i class="far fa-calendar-alt fa-fw post-meta-icon"></i><span class="post-meta-label">发表于</span><time class="post-meta-date-created" datetime="2022-12-05T17:00:00.000Z" title="发表于 2022-12-05 17:00:00">2022-12-05</time><span class="post-meta-separator">|</span><i class="fas fa-history fa-fw post-meta-icon"></i><span class="post-meta-label">更新于</span><time class="post-meta-date-updated" datetime="2023-08-30T18:00:49.037Z" title="更新于 2023-08-30 18:00:49">2023-08-30</time></span><span class="post-meta-categories"><span class="post-meta-separator">|</span><i class="fas fa-inbox fa-fw post-meta-icon"></i><a class="post-meta-categories" href="/categories/JavaScript%E7%AC%94%E8%AE%B0/">JavaScript笔记</a></span></div><div class="meta-secondline"><span class="post-meta-separator">|</span><span data-flag-title="JavaScript 第二天"><i class="far fa-eye fa-fw post-meta-icon"></i><span class="post-meta-label">阅读量:</span><span id="twikoo_visitors"><i class="fa-solid fa-spinner fa-spin"></i></span></span></div></div></div></header><main class="layout" id="content-inner"><div id="post"><article class="post-content" id="article-container"><h3 id="JavaScript-基础第二天"><a href="#JavaScript-基础第二天" class="headerlink" title="JavaScript 基础第二天"></a>JavaScript 基础第二天</h3><h3 id="算术运算符"><a href="#算术运算符" class="headerlink" title="算术运算符:"></a>算术运算符:</h3><ol><li>经常作为某个数字<strong>是否被整除</strong></li><li>数学运算也叫算术运算, 主要包括加、减、乘、除、取余(取模)</li><li>+：求和、-：求差、*：求积、&#x2F;：求商、%：取余</li></ol><img src="" data-lazy-src="https://cdn1.tianli0.top/gh/web-xc/iMG/postss/算术运算符.jpg" style="zoom:33%"><h4 id="算术运算符优先级顺序"><a href="#算术运算符优先级顺序" class="headerlink" title="算术运算符优先级顺序:"></a>算术运算符优先级顺序:</h4><ol><li><p>同时使用多个运算符写程序时, 会按某种顺序先后执行, 称为优先级</p></li><li><p>js中, 优先级<strong>越高越先被执行</strong>, 优先级相同时左向右执</p></li><li><p>乘、除、取余优先级相同, 加、减优先级相同</p></li><li><p>乘、除、取余优先级大于加、减</p></li><li><p>使用()可以提升优先级</p></li><li><p>总结: <strong>先乘除后加减，有括号先算括号里的</strong></p></li><li><p>计算圆的面积:</p></li></ol><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">let</span> num1 = <span class="title function_">prompt</span>(<span class="string">&#x27;请输入您的半径&#x27;</span>)</span><br><span class="line"><span class="keyword">let</span> num2 = <span class="number">3.14</span> * num1 * num1</span><br><span class="line"><span class="title function_">alert</span>(<span class="string">`计算之后圆的面积是: <span class="subst">$&#123;<span class="number">3.14</span> * num1 * num1&#125;</span>`</span>)</span><br><span class="line"><span class="title function_">alert</span>(<span class="string">`计算之后圆的面积是: <span class="subst">$&#123;num2&#125;</span>`</span>)</span><br></pre></td></tr></table></figure><hr><h3 id="赋值运算符"><a href="#赋值运算符" class="headerlink" title="赋值运算符:"></a>赋值运算符:</h3><ol><li><p>对变量进行赋值的运算符, 使用这些可对变量赋值时快速操作</p></li><li><p>学过的赋值运算：&#x3D; 将等号右边值赋予给左边, 要求左边必须是一个容器</p></li><li><p>其他赋值运算符: +&#x3D;, -&#x3D;, *&#x3D;, &#x2F;&#x3D;, %&#x3D;, let num &#x3D; 10 ， <strong>num加5 赋值写就是: num +&#x3D; 5</strong></p><img src="" data-lazy-src="https://cdn1.tianli0.top/gh/web-xc/iMG/postss/赋值运算符.jpg" style="zoom:33%"></li></ol><hr><h3 id="二元运算符"><a href="#二元运算符" class="headerlink" title="二元运算符:"></a>二元运算符:</h3><ol><li><strong>经常用于计数来使用</strong>, 比如进行10次操作，用它来计算进行多少次</li><li>众多js运算可根据所需表达式的个数，分为一元、二元、三元运算符</li><li>前置和后置自增<strong>单独使用没有区别</strong></li><li>前置和后置自增<strong>参与运算就有区别</strong></li><li>前置：<strong>先自增后运算</strong></li><li>后置：<strong>先运算后自增</strong></li></ol><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">let</span> num = <span class="number">10</span> + <span class="number">20</span></span><br></pre></td></tr></table></figure><ol><li>以前让一个变量每次+1 ，我们怎么做的呢？</li></ol><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">let</span> num = <span class="number">1</span></span><br><span class="line"><span class="keyword">let</span> = num + <span class="number">1</span></span><br><span class="line"><span class="comment">// 现在可以这样做</span></span><br><span class="line"><span class="keyword">let</span> num = <span class="number">1</span></span><br><span class="line">num += <span class="number">1</span></span><br></pre></td></tr></table></figure><img src="" data-lazy-src="https://cdn.staticaly.com/gh/web-xc/iMG@main/postss/%E4%BA%8C%E5%85%83%E8%BF%90%E7%AE%97%E7%AC%A6.jpg" style="zoom:33%"><h5 id="自增运算符的用法"><a href="#自增运算符的用法" class="headerlink" title="自增运算符的用法:"></a>自增运算符的用法:</h5><ol><li><p>一般开发中都是独立使用, 后面 i++ 后置自增会使用较多</p><img src="" data-lazy-src="https://cdn1.tianli0.top/gh/web-xc/iMG/postss/三元的前置和后置.jpg" style="zoom:33%"></li></ol><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 面试题 问: 输出结果是多少?</span></span><br><span class="line"><span class="keyword">let</span> num = <span class="number">10</span></span><br><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>(num++ + ++num + num)</span><br></pre></td></tr></table></figure><hr><h3 id="比较运算符"><a href="#比较运算符" class="headerlink" title="比较运算符:"></a>比较运算符:</h3><ol><li>比较两个数据大小、是否相等, 尽量不比较小数，因为小数有精度问题</li><li>NaN不等于任何值，包括它本身</li><li>不同类型之间比较会发生隐式转换, 最终把数据隐式转成number类型再比较</li><li>字符串比较，比较的字符对应的ASCII码, 从左往右依次比较</li></ol><h4 id="比较运算符的使用"><a href="#比较运算符的使用" class="headerlink" title="比较运算符的使用:"></a>比较运算符的使用:</h4><table><thead><tr><th align="left">&gt; ： 左边是否大于右边</th><th align="left">&lt;：左边是否小于右边</th></tr></thead><tbody><tr><td align="left">&gt;&#x3D;：左边是否大于等于右边</td><td align="left">&lt;&#x3D;：左边是否小于等于右边</td></tr><tr><td align="left">&#x3D;&#x3D;：左右两边是否相等 &#x3D;&#x3D;</td><td align="left">&#x3D;&#x3D;&#x3D;：左右两边是否<strong>类型和值都相等</strong></td></tr><tr><td align="left">!&#x3D;&#x3D;：左右两边是否<strong>不全等</strong></td><td align="left">比较结果为布尔型，只会得到true或false</td></tr></tbody></table><hr><h3 id="逻辑运算符"><a href="#逻辑运算符" class="headerlink" title="逻辑运算符:"></a>逻辑运算符:</h3><ol><li>逻辑运算符用来<strong>解决多重条件判断</strong></li></ol><table><thead><tr><th align="left">符号</th><th align="left">名称</th><th align="left">读法</th><th align="left">口诀</th><th align="left">特点</th></tr></thead><tbody><tr><td align="left">&amp;&amp;</td><td align="left">逻辑与</td><td align="left">并且</td><td align="left">一假则假</td><td align="left">两边都为true 结果才为true</td></tr><tr><td align="left">||</td><td align="left">逻辑或</td><td align="left">或者</td><td align="left">一真则真</td><td align="left">两边有一个true 结果为true</td></tr><tr><td align="left">!</td><td align="left">逻辑非</td><td align="left">取反</td><td align="left">真变假, 假变真</td><td align="left">true变false false变true</td></tr></tbody></table><h4 id="逻辑运算符里的短路"><a href="#逻辑运算符里的短路" class="headerlink" title="逻辑运算符里的短路:"></a>逻辑运算符里的短路:</h4><ol><li>只存在于**&amp;&amp;和||中**，当满足条件会让右边代码不执行</li><li>&amp;&amp;: 左边为false就短路、||: 左边为true就短路</li><li>原因：通过左边能得到整个式子结果，因此没必要再判断右边</li><li>运算结果: 无论&amp;&amp;还是|| ，结果都是最后被执行的表达式值，一般用在变量赋值</li></ol><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 五个短路: false 0 &#x27;&#x27; undefined null</span></span><br><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="literal">false</span> &amp;&amp; <span class="number">10</span>)</span><br><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="number">6</span> &gt; <span class="number">7</span> &amp;&amp; <span class="number">10</span>)</span><br><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="literal">undefined</span> &amp;&amp; <span class="number">10</span>)</span><br><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="literal">null</span> &amp;&amp; <span class="number">10</span>)</span><br><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="number">0</span> &amp;&amp; <span class="number">10</span>)</span><br><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="number">10</span> &amp;&amp; <span class="number">20</span>)</span><br></pre></td></tr></table></figure><ol><li>用户输入一个数, 判断一个数是4的倍数，且不是100的倍数:</li></ol><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">let</span> num = <span class="title function_">prompt</span>(<span class="string">&#x27;请输入一个数&#x27;</span>)</span><br><span class="line">nm1 = num || <span class="number">0</span></span><br><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>(num % <span class="number">4</span> === <span class="number">0</span> &amp;&amp; num % <span class="number">100</span> !== <span class="number">0</span>)</span><br></pre></td></tr></table></figure><hr><h4 id="运算符优先级"><a href="#运算符优先级" class="headerlink" title="运算符优先级:"></a>运算符优先级:</h4><ol><li><p>一元运算符里的<strong>逻辑非优先级很高</strong></p></li><li><p>逻辑与比逻辑或优先级高</p><img src="" data-lazy-src="https://cdn1.tianli0.top/gh/web-xc/iMG/postss/运算符优先级.jpg" style="zoom:25%"></li></ol><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// a为false 此时发生了逻辑与中断</span></span><br><span class="line"><span class="keyword">let</span> a = <span class="number">3</span> &gt; <span class="number">5</span> &amp;&amp; <span class="number">2</span> &lt; <span class="number">7</span> &amp;&amp; <span class="number">3</span> == <span class="number">4</span></span><br><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>(a)</span><br><span class="line"><span class="comment">// b为true 此时发生了逻辑或中断</span></span><br><span class="line"><span class="keyword">let</span> b = <span class="number">3</span> &lt;= <span class="number">4</span> || <span class="number">3</span> &gt; <span class="number">1</span> || <span class="number">3</span> != <span class="number">2</span></span><br><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>(b)</span><br><span class="line"><span class="comment">// c为false 数据类型不匹配</span></span><br><span class="line"><span class="keyword">let</span> c = <span class="number">2</span> === <span class="string">&#x27;2&#x27;</span></span><br><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>(c)</span><br><span class="line"><span class="comment">// d为true 此时发生了逻辑或中断</span></span><br><span class="line"><span class="keyword">let</span> d = !c || b &amp;&amp; a</span><br><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>(d)</span><br></pre></td></tr></table></figure><hr><h3 id="表达式和语句"><a href="#表达式和语句" class="headerlink" title="表达式和语句:"></a>表达式和语句:</h3><ol><li>表达式是一组代码的集合，js解释器会计算出一个结果</li><li>某些情况, 也可把表达式理解为语句, 因为它在计算结果, 也是做事</li><li>表达式是计算出一个值，语句用来自行使某件事发生(做什么事)</li><li>表达式: 3 + 4 , 语句: alert() 弹出对话框</li><li>js语句是以分号结束 (可省略) , 如: if语句 for循环</li></ol><hr><h3 id="分支语句"><a href="#分支语句" class="headerlink" title="分支语句:"></a>分支语句:</h3><ol><li><p>程序三大流程控制语句: 顺序, 分支, 循环</p></li><li><p>以前写代码，写几句就从上往下执行几句，这种叫<strong>顺序结构</strong></p></li><li><p>有时候根据条件选择执行代码，这种就叫<strong>分支结构</strong></p></li><li><p>某段代码被重复执行, 叫<strong>循环结构</strong></p></li><li><p>分支语句包含: if分支语句, 三元运算符, switch语句</p><img src="" data-lazy-src="https://cdn1.tianli0.top/gh/web-xc/iMG/postss/分支语句.jpg" style="zoom:33%"></li></ol><h3 id="1-if语句"><a href="#1-if语句" class="headerlink" title="1. if语句:"></a>1. if语句:</h3><ol><li>if语句有三种使用：单分支、双分支、多分支</li><li>括号内的条件为true时，就进入大括号里执行代码</li><li>小括号内的结果若不是布尔类型时，会发生隐式转换转为布尔类型</li></ol><h4 id="1-单分支if语法："><a href="#1-单分支if语法：" class="headerlink" title="1. 单分支if语法："></a>1. 单分支if语法：</h4><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// if括号里执行是布尔型, 可以是比较运算和字符串类型</span></span><br><span class="line"><span class="keyword">if</span> (条件) &#123;</span><br><span class="line">    <span class="title function_">alert</span>(<span class="string">&#x27;满足条件执行的代码&#x27;</span>)</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure><h4 id="2-双分支if语法"><a href="#2-双分支if语法" class="headerlink" title="2. 双分支if语法:"></a>2. 双分支if语法:</h4><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">let</span> num = +<span class="title function_">prompt</span>(<span class="string">&#x27;请输入年份&#x27;</span>)</span><br><span class="line"><span class="comment">// 能被4整除但不能被100整除，或被400整除的年份是闰年，否则都是平年</span></span><br><span class="line"><span class="keyword">if</span> (num % <span class="number">4</span> === <span class="number">0</span> &amp;&amp; num % <span class="number">100</span> !== <span class="number">0</span> || num % <span class="number">400</span> === <span class="number">0</span>) &#123;</span><br><span class="line">    <span class="title function_">alert</span>(<span class="string">`<span class="subst">$&#123;num&#125;</span>年是闰年`</span>)</span><br><span class="line">&#125; <span class="keyword">else</span> &#123;</span><br><span class="line"><span class="comment">// 不被4整除则执行是平年</span></span><br><span class="line">    <span class="title function_">alert</span>(<span class="string">`<span class="subst">$&#123;num&#125;</span>年是平年`</span>)</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure><h4 id="3-多分支if语法"><a href="#3-多分支if语法" class="headerlink" title="3. 多分支if语法:"></a>3. 多分支if语法:</h4><ol><li>先判断条件1, 若满足条件1就执行代码1, 其他不执行</li><li>若不满足则向下判断条件2, 满足条件2则执行代码2, 其他不执行</li><li>若依然不满足则继续往下判断, 依次类推</li><li>若以上条件都不满足, 则执行else里的代码, 可写N个条件</li></ol><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 根据输入不同时间，输出不同问候语</span></span><br><span class="line"><span class="keyword">let</span> num2 = +<span class="title function_">prompt</span>(<span class="string">&#x27;请输入当前时间: &#x27;</span>)</span><br><span class="line"><span class="keyword">if</span> (num2 &lt; <span class="number">12</span>) &#123;</span><br><span class="line">    <span class="title function_">alert</span>(<span class="string">&#x27;上午好, 好好工作&#x27;</span>)</span><br><span class="line">&#125; <span class="keyword">else</span> <span class="keyword">if</span> (num2 &lt; <span class="number">17</span>) &#123;</span><br><span class="line">    <span class="title function_">alert</span>(<span class="string">&#x27;下午好, 好好工作&#x27;</span>)</span><br><span class="line">&#125; <span class="keyword">else</span> <span class="keyword">if</span> (num2 &lt; <span class="number">19</span>) &#123;</span><br><span class="line">    <span class="title function_">alert</span>(<span class="string">&#x27;晚上好, 好好加班&#x27;</span>)</span><br><span class="line">&#125; <span class="keyword">else</span> &#123;</span><br><span class="line">    <span class="title function_">alert</span>(<span class="string">&#x27;夜深了~ 头发还有吗?&#x27;</span>)</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure><hr><h3 id="2-三元运算符"><a href="#2-三元运算符" class="headerlink" title="2. 三元运算符:"></a>2. 三元运算符:</h3><ol><li>符号：**? 与 :** 配合使用, 用来取值</li><li>其实是比if双分支更简单的写法, 也叫做<strong>三元表达</strong></li><li>语法：<strong>条件 ? 满足条件执行代码 : 不满足条件执行代码</strong></li></ol><h5 id="1-判断2个数的最大值"><a href="#1-判断2个数的最大值" class="headerlink" title="1. 判断2个数的最大值:"></a>1. 判断2个数的最大值:</h5><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">let</span> num1 = +<span class="title function_">prompt</span>(<span class="string">&#x27;请输入第一个数&#x27;</span>)</span><br><span class="line"><span class="keyword">let</span> num2 = +<span class="title function_">prompt</span>(<span class="string">&#x27;请输入第二个数&#x27;</span>)</span><br><span class="line"><span class="keyword">let</span> num3 = num1 &gt; num2 ? num1 : num2</span><br><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>(num3)</span><br></pre></td></tr></table></figure><h5 id="2-数字小于10补0"><a href="#2-数字小于10补0" class="headerlink" title="2. 数字小于10补0:"></a>2. 数字小于10补0:</h5><ol><li>用户输入1个数，如果数字小于10，则前面进行补0, 如: 01 02</li></ol><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">let</span> num1 = <span class="title function_">prompt</span>(<span class="string">&#x27;请输入一个数&#x27;</span>)</span><br><span class="line"><span class="keyword">let</span> num2 = num1 &gt;= <span class="number">10</span> ? num1 : <span class="string">&#x27;0&#x27;</span> + num1</span><br><span class="line"><span class="comment">// let num2 = num1 &lt; 10 ? &#x27;0&#x27; + num1 : num1</span></span><br><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>(num2)</span><br></pre></td></tr></table></figure><hr><h3 id="3-Switch-语句"><a href="#3-Switch-语句" class="headerlink" title="3. Switch 语句:"></a>3. Switch 语句:</h3><ol><li><strong>switch case语句用于等值判断</strong>, 不适合用于区间判断</li><li>switch case<strong>需要配合break关键字使用, 没有break会造成case穿透</strong></li><li>找到跟小括号里数据全等的case值，并执行里面对应的代码</li><li>若没有全等 &#x3D;&#x3D;&#x3D; 的则执行default里的代码</li><li>break: 结束switch语句，防止穿透</li></ol><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">switch</span> (<span class="number">1</span>) &#123;</span><br><span class="line">    <span class="keyword">case</span> <span class="number">1</span>:</span><br><span class="line">        <span class="title function_">alert</span>(<span class="string">&#x27;我是1&#x27;</span>)</span><br><span class="line">        <span class="keyword">break</span></span><br><span class="line">    <span class="keyword">case</span> <span class="number">2</span>:</span><br><span class="line">        <span class="title function_">alert</span>(<span class="string">&#x27;我是2&#x27;</span>)</span><br><span class="line">        <span class="keyword">break</span></span><br><span class="line">    <span class="keyword">case</span> <span class="number">3</span>:</span><br><span class="line">        <span class="title function_">alert</span>(<span class="string">&#x27;我是3&#x27;</span>)</span><br><span class="line">    <span class="attr">default</span>:</span><br><span class="line">        <span class="title function_">alert</span>(<span class="string">&#x27;没有数据&#x27;</span>)</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure><p><strong>简单计算器:</strong></p><ol><li>用户输入2个数字, 然后输入+ - * &#x2F;，可执行不同运算结果</li></ol><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">let</span> num1 = +<span class="title function_">prompt</span>(<span class="string">&#x27;请输入第一个数&#x27;</span>)</span><br><span class="line"><span class="keyword">let</span> num2 = +<span class="title function_">prompt</span>(<span class="string">&#x27;请输入第二个数&#x27;</span>)</span><br><span class="line"><span class="keyword">let</span> num3 = <span class="title function_">prompt</span>(<span class="string">&#x27;请输入想要的运算: + - * /&#x27;</span>)</span><br><span class="line"><span class="keyword">switch</span> (num3) &#123;</span><br><span class="line">    <span class="keyword">case</span> <span class="string">&#x27;+&#x27;</span>:</span><br><span class="line">        <span class="title function_">alert</span>(<span class="string">`你输入了+运算, 两个数结果为<span class="subst">$&#123;num1 + num2&#125;</span>`</span>)</span><br><span class="line">        <span class="keyword">break</span></span><br><span class="line">    <span class="keyword">case</span> <span class="string">&#x27;-&#x27;</span>:</span><br><span class="line">        <span class="title function_">alert</span>(<span class="string">`你输入了-运算, 两个数结果为<span class="subst">$&#123;num1 - num2&#125;</span>`</span>)</span><br><span class="line">        <span class="keyword">break</span></span><br><span class="line">    <span class="keyword">case</span> <span class="string">&#x27;*&#x27;</span>:</span><br><span class="line">        <span class="title function_">alert</span>(<span class="string">`你输入了*运算, 两个数结果为<span class="subst">$&#123;num1 * num2&#125;</span>`</span>)</span><br><span class="line">        <span class="keyword">break</span></span><br><span class="line">    <span class="keyword">case</span> <span class="string">&#x27;/&#x27;</span>:</span><br><span class="line">        <span class="title function_">alert</span>(<span class="string">`你输入了/运算, 两个数结果为<span class="subst">$&#123;num1 / num2&#125;</span>`</span>)</span><br><span class="line">        <span class="keyword">break</span></span><br><span class="line">    <span class="attr">default</span>:</span><br><span class="line">        <span class="title function_">alert</span>(<span class="string">&#x27;你输入了啥? 请在 + - * / 中选择&#x27;</span>)</span><br><span class="line">&#125; </span><br></pre></td></tr></table></figure><hr><h3 id="4-循环结构"><a href="#4-循环结构" class="headerlink" title="4. 循环结构:"></a>4. 循环结构:</h3><ol><li><p>学习时可帮助更好理解代码运行, 工作时可更快找到bug</p></li><li><p>断点: 在某句代码上加标记叫断点, 程序执行到这句有标记的代码时会暂停下来</p></li></ol><img src="" data-lazy-src="https://cdn.staticaly.com/gh/web-xc/iMG@main/postss/%E6%96%AD%E7%82%B9%E8%B0%83%E8%AF%95.jpg" style="zoom:33%"><h4 id="While-循环"><a href="#While-循环" class="headerlink" title="While 循环:"></a>While 循环:</h4><ol><li><p>循环: 重复执行某段代码</p></li><li><p>跟if语句很像，都要满足小括号里的条件为true才会执行代码</p></li><li><p>while大括号里代码执行完毕后不会跳出，而是继续回到小括号里判断条件是否满足，若满足又执行大括号里的代码，然后再回到小括号判断条件, 直到括号内条件不满足,即跳出</p></li><li><p>循环的本质就是以某个变量为起始值, 然后不断产生变化量, 慢慢靠近终止条件的过程</p></li></ol><p><strong>循环需要具备三要素</strong>：</p><ol><li>变量起始值</li><li>终止条件 (没有终止条件, 循环会一直执行, 造成死循环</li><li>变量变化量 (自增或自减)</li></ol><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 1.变量的起始值</span></span><br><span class="line"><span class="keyword">let</span> num = <span class="number">1</span></span><br><span class="line"><span class="comment">// 2.终止条件 循环条件</span></span><br><span class="line"><span class="keyword">while</span> (num &lt;= <span class="number">5</span>) &#123;</span><br><span class="line"><span class="comment">// 4.重复执行的代码(循环体)</span></span><br><span class="line">    <span class="variable language_">document</span>.<span class="title function_">write</span>(<span class="string">&#x27;你好&#x27;</span>)</span><br><span class="line"><span class="comment">// 3.变量变化</span></span><br><span class="line">    num++</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure><ol><li>页面输出1-10:</li></ol><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">let</span> num = <span class="number">1</span></span><br><span class="line"><span class="keyword">while</span> (num &lt;= <span class="number">10</span>) &#123;</span><br><span class="line">    <span class="variable language_">document</span>.<span class="title function_">write</span>(num)</span><br><span class="line">    num++</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure><ol start="2"><li>计算从1加到100总和并输出</li></ol><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 声明累加和的变量num2, 每次把num1加到num2里</span></span><br><span class="line"><span class="keyword">let</span> num1 = <span class="number">1</span></span><br><span class="line"><span class="keyword">let</span> num2 = <span class="number">0</span></span><br><span class="line"><span class="keyword">while</span> (num1 &lt;= <span class="number">10</span>) &#123;</span><br><span class="line">    num2 += num1</span><br><span class="line">    num1++</span><br><span class="line">&#125;</span><br><span class="line"><span class="variable language_">document</span>.<span class="title function_">write</span>(num2)</span><br></pre></td></tr></table></figure><ol start="3"><li>计算1-100之间所有偶数的和</li></ol><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 首先利用if语句把num1里是偶数筛选出来, 把筛选的num1加到num2里</span></span><br><span class="line"><span class="keyword">let</span> num1 = <span class="number">1</span></span><br><span class="line"><span class="keyword">let</span> num2 = <span class="number">0</span></span><br><span class="line"><span class="keyword">while</span> (num1 &lt;=<span class="number">10</span>) &#123;</span><br><span class="line">    <span class="keyword">if</span> (num1 % <span class="number">2</span> === <span class="number">0</span>) &#123;</span><br><span class="line">        num2 += num1</span><br><span class="line">    &#125;</span><br><span class="line">    num1++</span><br><span class="line">&#125;</span><br><span class="line"><span class="variable language_">document</span>.<span class="title function_">write</span>(num2)</span><br></pre></td></tr></table></figure><ol start="4"><li>弹出对话框，‘你喜欢我吗’，如果输‘喜欢’, 则结束, 否则一直弹出对话框:</li></ol><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">while</span> (<span class="literal">true</span>) &#123;</span><br><span class="line">    <span class="keyword">let</span> num = <span class="title function_">prompt</span>(<span class="string">&#x27;我喜欢你, 你喜欢我吗?&#x27;</span>)</span><br><span class="line">    <span class="keyword">if</span> (num === <span class="string">&#x27;喜欢&#x27;</span>) &#123;</span><br><span class="line">        <span class="title function_">alert</span>(<span class="string">&#x27;我也喜欢你&#x27;</span>)</span><br><span class="line">        <span class="keyword">break</span></span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure><ol start="5"><li>用户登录验证, 输入用户名和密码</li></ol><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 若用户名为admin, 且密码为123456, 则提示登录成功, 否则让用户一直输入</span></span><br><span class="line"><span class="keyword">let</span> username = <span class="title function_">prompt</span>(<span class="string">&#x27;请输入用户名&#x27;</span>)</span><br><span class="line"><span class="keyword">let</span> password = <span class="title function_">prompt</span>(<span class="string">&#x27;请输入密码&#x27;</span>)</span><br><span class="line"><span class="keyword">while</span> (<span class="literal">true</span>) &#123;</span><br><span class="line"><span class="keyword">if</span> (username == <span class="string">&#x27;admin&#x27;</span> &amp;&amp; password == <span class="number">123456</span>)</span><br><span class="line">    &#123;</span><br><span class="line">        <span class="title function_">alert</span>(<span class="string">&#x27;登录成功&#x27;</span>)</span><br><span class="line">        <span class="keyword">break</span></span><br><span class="line">    &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">        <span class="title function_">alert</span>(<span class="string">&#x27;用户名或密码错误, 请重新输入&#x27;</span>)</span><br><span class="line">        <span class="keyword">let</span> username = <span class="title function_">prompt</span>(<span class="string">&#x27;请输入用户名&#x27;</span>)</span><br><span class="line">        <span class="keyword">let</span> password = <span class="title function_">prompt</span>(<span class="string">&#x27;请输入密码&#x27;</span>)</span><br><span class="line">    <span class="keyword">if</span> (username == <span class="string">&#x27;admin&#x27;</span> &amp;&amp; password == <span class="number">123456</span>) &#123;</span><br><span class="line">        <span class="title function_">alert</span>(<span class="string">&#x27;登录成功&#x27;</span>)</span><br><span class="line">        <span class="keyword">break</span></span><br><span class="line">    &#125;            </span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure><ol start="6"><li>求1-100之间个位数不为3的数累加和</li></ol><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">let</span> num1 = <span class="number">1</span></span><br><span class="line"><span class="keyword">let</span> num2 = <span class="number">0</span></span><br><span class="line"><span class="keyword">while</span> (num1 &lt;= <span class="number">100</span>) &#123;</span><br><span class="line">    <span class="keyword">if</span> (num1 % <span class="number">10</span> !== <span class="number">3</span>) &#123;</span><br><span class="line">        num2 += num1</span><br><span class="line">    &#125;</span><br><span class="line">    num1++</span><br><span class="line">&#125;</span><br><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>(num2)</span><br></pre></td></tr></table></figure><h3 id="5-循环退出-continue和break的区别"><a href="#5-循环退出-continue和break的区别" class="headerlink" title="5. 循环退出: continue和break的区别"></a>5. 循环退出: continue和break的区别</h3><ol><li>continue：结束本次循环, 继续下次循环</li><li>break：跳出所在的循环</li></ol><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">let</span> num1 = <span class="number">1</span></span><br><span class="line"><span class="keyword">while</span> (num1 &lt;= <span class="number">6</span>) &#123;</span><br><span class="line">    <span class="keyword">if</span> (num1 === <span class="number">2</span>) &#123;</span><br><span class="line">        num1++</span><br><span class="line">        <span class="comment">// 结束本次循环, 继续下次循环</span></span><br><span class="line">        <span class="keyword">continue</span></span><br><span class="line">        <span class="comment">// 退出循环</span></span><br><span class="line">        <span class="comment">// break</span></span><br><span class="line">    &#125;</span><br><span class="line">    <span class="variable language_">document</span>.<span class="title function_">write</span>(<span class="string">`我吃了<span class="subst">$&#123;num1&#125;</span>个苹果&lt;br&gt;`</span>)</span><br><span class="line">    num1++</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure><h5 id="ATM取款机案例"><a href="#ATM取款机案例" class="headerlink" title="ATM取款机案例:"></a>ATM取款机案例:</h5><ol><li>输入不同的值, 用Switch来执行不同的操作</li><li>用户可存钱、取钱、查看余额和退出</li><li>循环的时候, 需反复提示输入框, 所以提示框写到循环里</li><li>退出条件是用户输入 4, 如果是4, 则结束循环, 不再弹窗</li><li>提前准备100金额预先存储一个数额</li><li>取钱存钱则用加减法, 查看余额则直接显示金额</li></ol><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 3. 金额的变量, 先存储100</span></span><br><span class="line"><span class="keyword">let</span> money = <span class="number">100</span></span><br><span class="line"><span class="comment">// 1. 不断弹出对话框</span></span><br><span class="line"><span class="keyword">while</span> (<span class="literal">true</span>) &#123;</span><br><span class="line">    <span class="keyword">let</span> operate = <span class="title function_">prompt</span>(<span class="string">`</span></span><br><span class="line"><span class="string">    请输入您的操作:</span></span><br><span class="line"><span class="string">    1. 取钱</span></span><br><span class="line"><span class="string">    2. 存钱</span></span><br><span class="line"><span class="string">    3. 查看余额</span></span><br><span class="line"><span class="string">    4. 退出</span></span><br><span class="line"><span class="string">    `</span>)</span><br><span class="line"><span class="comment">// 2. 输入4退出对话框 不输入则死循环弹出对话框</span></span><br><span class="line"><span class="keyword">if</span> (operate === <span class="string">&#x27;4&#x27;</span>) &#123;</span><br><span class="line">    <span class="keyword">break</span></span><br><span class="line">&#125; </span><br><span class="line"><span class="comment">// 4. 用switch实现取钱存钱操作</span></span><br><span class="line"><span class="keyword">switch</span> (operate) &#123;</span><br><span class="line">    <span class="keyword">case</span> <span class="string">&#x27;1&#x27;</span>:</span><br><span class="line">        <span class="keyword">let</span> take = +<span class="title function_">prompt</span>(<span class="string">&#x27;请输入取钱金额:&#x27;</span>)</span><br><span class="line">        money -= take</span><br><span class="line">        <span class="keyword">break</span></span><br><span class="line">    <span class="keyword">case</span> <span class="string">&#x27;2&#x27;</span>:</span><br><span class="line">        <span class="keyword">let</span> deposit = +<span class="title function_">prompt</span>(<span class="string">&#x27;请输入存钱金额:&#x27;</span>)</span><br><span class="line">        money += deposit</span><br><span class="line">        <span class="keyword">break</span></span><br><span class="line">    <span class="keyword">case</span> <span class="string">&#x27;3&#x27;</span>:</span><br><span class="line">        <span class="keyword">let</span> see = <span class="title function_">alert</span>(<span class="string">`您的金额还有<span class="subst">$&#123;money&#125;</span>`</span>)</span><br><span class="line">        <span class="keyword">break</span></span><br><span class="line">&#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure><hr><h4 id="本节单词"><a href="#本节单词" class="headerlink" title="本节单词:"></a>本节单词:</h4><ol><li>if</li><li>else</li><li>switch</li><li>case</li><li>while</li><li>continue</li><li>break</li><li>default</li></ol></article><div class="post-copyright"><div class="post-copyright__author"><span class="post-copyright-meta">本文作者:</span> <span class="post-copyright-info"><a href="https://webxc.eu.org">XC's Blog</a></span></div><div class="post-copyright__type"><span class="post-copyright-meta">本文链接:</span> <span class="post-copyright-info"><a href="https://webxc.eu.org/post/623e/">https://webxc.eu.org/post/623e/</a></span></div><div class="post-copyright__notice"><span class="post-copyright-meta">版权声明:</span> <span class="post-copyright-info">本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" target="_blank">CC BY-NC-SA 4.0</a> 许可协议。转载请注明来自 <a href="https://webxc.eu.org" target="_blank">XC's Blog</a>！</span></div></div><div class="tag_share"><div class="post-meta__tag-list"><a class="post-meta__tags" href="/tags/JavaScript%E7%AC%94%E8%AE%B0/">JavaScript笔记</a></div><div class="post_share"><div class="social-share" data-image="https://npm.elemecdn.com/webxc/cover/js1.webp" data-sites="facebook,twitter,wechat,weibo,qq"></div><link rel="stylesheet" href="https://npm.elemecdn.com/butterfly-extsrc/sharejs/dist/css/share.min.css" media="print" onload='this.media="all"'><script src="https://npm.elemecdn.com/butterfly-extsrc/sharejs/dist/js/social-share.min.js" defer></script></div></div><div class="post-reward"><div class="reward-button"><i class="fas fa-qrcode"></i> 打赏</div><div class="reward-main"><ul class="reward-all"><li class="reward-item"><a href="https://npm.elemecdn.com/webxc@1.0.0/lxfs/wechat.png" target="_blank"><img class="post-qr-code-img" src="https://npm.elemecdn.com/webxc@1.0.0/lxfs/wechat.png" alt="Wechat"></a><div class="post-qr-code-desc">Wechat</div></li><li class="reward-item"><a href="https://npm.elemecdn.com/webxc@1.0.0/lxfs/alipay.jpg" target="_blank"><img class="post-qr-code-img" src="https://npm.elemecdn.com/webxc@1.0.0/lxfs/alipay.jpg" alt="Alipay"></a><div class="post-qr-code-desc">Alipay</div></li></ul></div></div><nav class="pagination-post" id="pagination"><div class="prev-post pull-left"><a href="/post/f244/"><img class="prev-cover" src="https://npm.elemecdn.com/webxc/cover/js1.webp" onerror='onerror=null,src="https://npm.elemecdn.com/webxc@1.0.2/banner/404.gif"' alt="cover of previous post"><div class="pagination-info"><div class="label">上一篇文章</div><div class="prev_info">JavaScript 第一天</div></div></a></div><div class="next-post pull-right"><a href="/post/6e+47/"><img class="next-cover" src="https://npm.elemecdn.com/webxc/cover/js1.webp" onerror='onerror=null,src="https://npm.elemecdn.com/webxc@1.0.2/banner/404.gif"' alt="cover of next post"><div class="pagination-info"><div class="label">下一篇文章</div><div class="next_info">JavaScript 第三天</div></div></a></div></nav><div class="relatedPosts"><div class="headline"><i class="fas fa-thumbs-up fa-fw"></i><span>相关推荐</span></div><div class="relatedPosts-list"><div><a href="/post/f244/" title="JavaScript 第一天"><img class="cover" src="https://npm.elemecdn.com/webxc/cover/js1.webp" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2022-11-22</div><div class="title">JavaScript 第一天</div></div></a></div><div><a href="/post/6e+47/" title="JavaScript 第三天"><img class="cover" src="https://npm.elemecdn.com/webxc/cover/js1.webp" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2022-12-27</div><div class="title">JavaScript 第三天</div></div></a></div><div><a href="/post/fd38/" title="JavaScript 第五天"><img class="cover" src="https://npm.elemecdn.com/webxc/cover/js1.webp" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2023-02-16</div><div class="title">JavaScript 第五天</div></div></a></div></div></div><hr><div id="post-comment"><div class="comment-head"><div class="comment-headline"><i class="fas fa-comments fa-fw"></i> <span>评论</span></div></div><div class="comment-wrap"><div><div id="twikoo-wrap"></div></div></div></div></div><div class="aside-content" id="aside-content"><div class="card-widget card-info"><div class="is-center"><div class="avatar-img"><img src="https://npm.elemecdn.com/webxc@1.0.0/logo/logo.jpg" onerror='this.onerror=null,this.src="https://npm.elemecdn.com/webxc@1.0.2/banner/404.gif"' alt="avatar"></div><div class="author-info__name">XC's Blog</div><div class="author-info__description">XC's Blog 记录生活和学习文章</div></div><div class="card-info-data site-data is-center"><a href="/archives/"><div class="headline">文章</div><div class="length-num">95</div></a><a href="/tags/"><div class="headline">标签</div><div class="length-num">25</div></a><a href="/categories/"><div class="headline">分类</div><div class="length-num">25</div></a></div><div class="card-info-social-icons is-center"><a class="social-icon" href="https://tenapi.cn/qqzlk/?qq=2848141597" target="_blank" title="QQ"><i class="iconfont icon-QQ"></i></a><a class="social-icon" href="https://npm.elemecdn.com/webxc@1.0.0/lxfs/wechat.jpg" target="_blank" title="微信"><i class="iconfont icon-weixin"></i></a><a class="social-icon" href="https://github.com/web-xc" target="_blank" title="Github"><i class="iconfont icon-github"></i></a><a class="social-icon" href="https://space.bilibili.com/2134826455" target="_blank" title="BiliBili"><i class="iconfont icon-bilibili"></i></a><a class="social-icon" href="https://music.163.com/#/user/home?id=323682437" target="_blank" title="网易云音乐"><i class="iconfont icon-wyy"></i></a></div></div><div class="card-widget card-announcement"><div class="item-headline"><i class="fas fa-bullhorn fa-shake"></i><span>公告</span></div><div class="announcement_content">原网站因使用.ml域名被回收, 再加上本人因学习原因, 没怎么打理博客, 使用了https://webxc.eu.org域名来维持博客运行, 如果有加友联的朋友们, 去友联页看信息即可, 如果原来有加过的, 麻烦在原来域名后缀改一下(.ml ==> .eu.org)就行, 博客写的太乱了, 没时间打理, 兄弟们谅解😁😁~~</div></div><div class="sticky_layout"><div class="card-widget" id="card-toc"><div class="item-headline"><i class="fas fa-stream"></i><span>目录</span><span class="toc-percentage"></span></div><div class="toc-content"><ol class="toc"><li class="toc-item toc-level-3"><a class="toc-link" href="#JavaScript-%E5%9F%BA%E7%A1%80%E7%AC%AC%E4%BA%8C%E5%A4%A9"><span class="toc-number">1.</span> <span class="toc-text">JavaScript 基础第二天</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E7%AE%97%E6%9C%AF%E8%BF%90%E7%AE%97%E7%AC%A6"><span class="toc-number">2.</span> <span class="toc-text">算术运算符:</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#%E7%AE%97%E6%9C%AF%E8%BF%90%E7%AE%97%E7%AC%A6%E4%BC%98%E5%85%88%E7%BA%A7%E9%A1%BA%E5%BA%8F"><span class="toc-number">2.1.</span> <span class="toc-text">算术运算符优先级顺序:</span></a></li></ol></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E8%B5%8B%E5%80%BC%E8%BF%90%E7%AE%97%E7%AC%A6"><span class="toc-number">3.</span> <span class="toc-text">赋值运算符:</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E4%BA%8C%E5%85%83%E8%BF%90%E7%AE%97%E7%AC%A6"><span class="toc-number">4.</span> <span class="toc-text">二元运算符:</span></a><ol class="toc-child"><li class="toc-item toc-level-5"><a class="toc-link" href="#%E8%87%AA%E5%A2%9E%E8%BF%90%E7%AE%97%E7%AC%A6%E7%9A%84%E7%94%A8%E6%B3%95"><span class="toc-number">4.0.1.</span> <span class="toc-text">自增运算符的用法:</span></a></li></ol></li></ol><li class="toc-item toc-level-3"><a class="toc-link" href="#%E6%AF%94%E8%BE%83%E8%BF%90%E7%AE%97%E7%AC%A6"><span class="toc-number">5.</span> <span class="toc-text">比较运算符:</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#%E6%AF%94%E8%BE%83%E8%BF%90%E7%AE%97%E7%AC%A6%E7%9A%84%E4%BD%BF%E7%94%A8"><span class="toc-number">5.1.</span> <span class="toc-text">比较运算符的使用:</span></a></li></ol></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E9%80%BB%E8%BE%91%E8%BF%90%E7%AE%97%E7%AC%A6"><span class="toc-number">6.</span> <span class="toc-text">逻辑运算符:</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#%E9%80%BB%E8%BE%91%E8%BF%90%E7%AE%97%E7%AC%A6%E9%87%8C%E7%9A%84%E7%9F%AD%E8%B7%AF"><span class="toc-number">6.1.</span> <span class="toc-text">逻辑运算符里的短路:</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E8%BF%90%E7%AE%97%E7%AC%A6%E4%BC%98%E5%85%88%E7%BA%A7"><span class="toc-number">6.2.</span> <span class="toc-text">运算符优先级:</span></a></li></ol></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E8%A1%A8%E8%BE%BE%E5%BC%8F%E5%92%8C%E8%AF%AD%E5%8F%A5"><span class="toc-number">7.</span> <span class="toc-text">表达式和语句:</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%88%86%E6%94%AF%E8%AF%AD%E5%8F%A5"><span class="toc-number">8.</span> <span class="toc-text">分支语句:</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#1-if%E8%AF%AD%E5%8F%A5"><span class="toc-number">9.</span> <span class="toc-text">1. if语句:</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#1-%E5%8D%95%E5%88%86%E6%94%AFif%E8%AF%AD%E6%B3%95%EF%BC%9A"><span class="toc-number">9.1.</span> <span class="toc-text">1. 单分支if语法：</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#2-%E5%8F%8C%E5%88%86%E6%94%AFif%E8%AF%AD%E6%B3%95"><span class="toc-number">9.2.</span> <span class="toc-text">2. 双分支if语法:</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#3-%E5%A4%9A%E5%88%86%E6%94%AFif%E8%AF%AD%E6%B3%95"><span class="toc-number">9.3.</span> <span class="toc-text">3. 多分支if语法:</span></a></li></ol></li><li class="toc-item toc-level-3"><a class="toc-link" href="#2-%E4%B8%89%E5%85%83%E8%BF%90%E7%AE%97%E7%AC%A6"><span class="toc-number">10.</span> <span class="toc-text">2. 三元运算符:</span></a><ol class="toc-child"><li class="toc-item toc-level-5"><a class="toc-link" href="#1-%E5%88%A4%E6%96%AD2%E4%B8%AA%E6%95%B0%E7%9A%84%E6%9C%80%E5%A4%A7%E5%80%BC"><span class="toc-number">10.0.1.</span> <span class="toc-text">1. 判断2个数的最大值:</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#2-%E6%95%B0%E5%AD%97%E5%B0%8F%E4%BA%8E10%E8%A1%A50"><span class="toc-number">10.0.2.</span> <span class="toc-text">2. 数字小于10补0:</span></a></li></ol></li><li class="toc-item toc-level-3"><a class="toc-link" href="#3-Switch-%E8%AF%AD%E5%8F%A5"><span class="toc-number">11.</span> <span class="toc-text">3. Switch 语句:</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#4-%E5%BE%AA%E7%8E%AF%E7%BB%93%E6%9E%84"><span class="toc-number">12.</span> <span class="toc-text">4. 循环结构:</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#While-%E5%BE%AA%E7%8E%AF"><span class="toc-number">12.1.</span> <span class="toc-text">While 循环:</span></a></li></ol></li><li class="toc-item toc-level-3"><a class="toc-link" href="#5-%E5%BE%AA%E7%8E%AF%E9%80%80%E5%87%BA-continue%E5%92%8Cbreak%E7%9A%84%E5%8C%BA%E5%88%AB"><span class="toc-number">13.</span> <span class="toc-text">5. 循环退出: continue和break的区别</span></a><ol class="toc-child"><li class="toc-item toc-level-5"><a class="toc-link" href="#ATM%E5%8F%96%E6%AC%BE%E6%9C%BA%E6%A1%88%E4%BE%8B"><span class="toc-number">13.0.1.</span> <span class="toc-text">ATM取款机案例:</span></a></li></ol></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E6%9C%AC%E8%8A%82%E5%8D%95%E8%AF%8D"><span class="toc-number">13.1.</span> <span class="toc-text">本节单词:</span></a></li></div></div><div class="card-widget card-recent-post"><div class="item-headline"><i class="fas fa-history"></i><span>最新文章</span></div><div class="aside-list"><div class="aside-list-item"><a class="thumbnail" href="/post/ds2s/" title="整个前端面试题"><img src="https://cdn1.tianli0.top/gh/web-xc/iMG/postss/vue.png" onerror='this.onerror=null,this.src="https://npm.elemecdn.com/webxc@1.0.2/banner/404.gif"' alt="整个前端面试题"></a><div class="content"><a class="title" href="/post/ds2s/" title="整个前端面试题">整个前端面试题</a><time datetime="2023-08-31T02:00:00.000Z" title="发表于 2023-08-31 02:00:00">2023-08-31</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/post/ds23/" title="常见前端面试题"><img src="https://cdn1.tianli0.top/gh/web-xc/iMG/postss/vue.png" onerror='this.onerror=null,this.src="https://npm.elemecdn.com/webxc@1.0.2/banner/404.gif"' alt="常见前端面试题"></a><div class="content"><a class="title" href="/post/ds23/" title="常见前端面试题">常见前端面试题</a><time datetime="2023-08-28T18:30:00.000Z" title="发表于 2023-08-28 18:30:00">2023-08-28</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/post/fe33/" title="硅谷甄选运营平台"><img src="https://cdn1.tianli0.top/gh/web-xc/iMG/postss/vue.png" onerror='this.onerror=null,this.src="https://npm.elemecdn.com/webxc@1.0.2/banner/404.gif"' alt="硅谷甄选运营平台"></a><div class="content"><a class="title" href="/post/fe33/" title="硅谷甄选运营平台">硅谷甄选运营平台</a><time datetime="2023-07-26T03:55:00.000Z" title="发表于 2023-07-26 03:55:00">2023-07-26</time></div></div></div></div></div></div></main><footer id="footer"><div id="footer-wrap"><div class="copyright">&copy;2021 - 2023 By XC's Blog</div><div class="framework-info"><span></span> <a target="_blank" rel="noopener" href="https://icp.gov.moe/?keyword=20235221">萌ICP备20235221号</a><span class="footer-separator">|</span><span></span> <a target="_blank" rel="noopener" href="https://icp.gov.moe/">萌ICP查询</a><div id="running-time"></div></div><script>setInterval((()=>{let e=Math.round(new Date("2021-11-21 01:35:06").getTime()/1e3),t=Math.round(((new Date).getTime()+288e5)/1e3)-e,n=new Array(0,0,0,0,0);t>=31536e3&&(n[0]=parseInt(t/31536e3),t%=31536e3),t>=86400&&(n[1]=parseInt(t/86400),t%=86400),t>=3600&&(n[2]=parseInt(t/3600),t%=3600),t>=60&&(n[3]=parseInt(t/60),t%=60),t>0&&(n[4]=t),currentTimeHtml="本站已安全运行 "+n[0]+" 年 "+n[1]+" 天 "+n[2]+" 时 "+n[3]+" 分 "+n[4]+" 秒",document.getElementById("running-time").innerHTML=currentTimeHtml}),1e3)</script></div></footer></div><div id="rightside"><div id="rightside-config-hide"><button id="readmode" type="button" title="阅读模式"><i class="fas fa-book-open"></i></button><button id="darkmode" type="button" title="浅色和深色模式转换"><i class="fas fa-adjust"></i></button><button id="hide-aside-btn" type="button" title="单栏和双栏切换"><i class="fas fa-arrows-alt-h"></i></button></div><div id="rightside-config-show"><button id="rightside_config" type="button" title="设置"><i class="fas fa-cog fa-spin"></i></button><button class="close" id="mobile-toc-button" type="button" title="目录"><i class="fas fa-list-ul"></i></button><a id="to_comment" href="#post-comment" title="直达评论"><i class="fas fa-comments"></i></a><button id="go-up" type="button" title="回到顶部"><i class="fas fa-arrow-up"></i><span id="percent">0<span>%</span></span></button><button id="go-down" type="button" title="直达底部" onclick="btf.scrollToDest(document.body.scrollHeight,500)"><i class="fas fa-arrow-down"></i></button></div></div><div id="local-search"><div class="search-dialog"><nav class="search-nav"><span class="search-dialog-title">搜索</span><span id="loading-status"></span><button class="search-close-button"><i class="fas fa-times"></i></button></nav><div class="is-center" id="loading-database"><i class="fas fa-spinner fa-pulse"></i> <span>正在载入文件,请稍后</span></div><div class="search-wrap"><div id="local-search-input"><div class="local-search-box"><input class="local-search-box--input" placeholder="搜索文章" type="text"></div></div><hr><div id="local-search-results"></div></div></div><div id="search-mask"></div></div><div><script src="https://npm.elemecdn.com/hexo-theme-butterfly/source/js/utils.js"></script><script src="https://npm.elemecdn.com/hexo-theme-butterfly@4.4.0/source/js/main.js"></script><script src="https://npm.elemecdn.com/@fancyapps/ui/dist/fancybox.umd.js"></script><script src="https://npm.elemecdn.com/instant.page/instantpage.js" type="module"></script><script src="https://npm.elemecdn.com/vanilla-lazyload/dist/lazyload.iife.min.js"></script><script src="https://npm.elemecdn.com/node-snackbar/dist/snackbar.min.js"></script><script src="https://npm.elemecdn.com/hexo-theme-butterfly/source/js/search/local-search.js"></script><div class="js-pjax"><script>(()=>{const e=document.querySelectorAll("#article-container .mermaid-wrap");if(e.length){window.runMermaid=()=>{window.loadMermaid=!0;const t="dark"===document.documentElement.getAttribute("data-theme")?"dark":"default";Array.from(e).forEach(((e,n)=>{const d=e.firstElementChild,r="mermaid-"+n,m="%%{init:{ 'theme':'"+t+"'}}%%\n"+d.textContent;mermaid.mermaidAPI.render(r,m,(e=>{d.insertAdjacentHTML("afterend",e)}))}))};const t=()=>{window.loadMermaid?runMermaid():getScript("https://npm.elemecdn.com/mermaid/dist/mermaid.min.js").then(runMermaid)};window.pjax?t():document.addEventListener("DOMContentLoaded",t)}})()</script><script>(()=>{const o=()=>{twikoo.init(Object.assign({el:"#twikoo-wrap",envId:"https://blog2.webxc.eu.org/",region:"",onCommentLoaded:function(){btf.loadLightbox(document.querySelectorAll("#twikoo .tk-content img:not(.tk-owo-emotion)"))}},null))},t=()=>{"object"!=typeof twikoo?getScript("https://npm.elemecdn.com/twikoo@1.6.16/dist/twikoo.all.min.js").then(o):setTimeout(o,0)};t()})()</script></div><script data-pjax="false" defer src="https://npm.elemecdn.com/webxc@1.0.16/css/style.js"></script><script defer src="https://npm.elemecdn.com/hexo-theme-butterfly@4.4.0/source/js/search/local-search.js"></scrip><script src="https://npm.elemecdn.com/butterfly-extsrc/dist/activate-power-mode.min.js"></script><script>POWERMODE.colorful=!0,POWERMODE.shake=!0,POWERMODE.mobile=!0,document.body.addEventListener("input",POWERMODE)</script><script src="https://npm.elemecdn.com/pjax@0.2.8/pjax.min.js"></script><script>let pjaxSelectors=["head > title","#config-diff","#body-wrap","#rightside-config-hide","#rightside-config-show",".js-pjax",".tk-comments-container"];var pjax=new Pjax({elements:'a:not([target="_blank"])',selectors:pjaxSelectors,cacheBust:!1,analytics:!1,scrollRestoration:!1});document.addEventListener("pjax:send",(function(){if(window.tocScrollFn&&window.removeEventListener("scroll",window.tocScrollFn),window.scrollCollect&&window.removeEventListener("scroll",scrollCollect),"object"==typeof preloader&&preloader.initLoading(),document.getElementById("rightside").style.cssText="opacity: ''; transform: ''",window.aplayers)for(let e=0;e<window.aplayers.length;e++)window.aplayers[e].options.fixed||window.aplayers[e].destroy();"object"==typeof typed&&typed.destroy();const e=document.body.classList;e.contains("read-mode")&&e.remove("read-mode"),"object"==typeof disqusjs&&disqusjs.destroy()})),document.addEventListener("pjax:complete",(function(){window.refreshFn(),document.querySelectorAll("script[data-pjax]").forEach((e=>{const t=document.createElement("script"),o=e.text||e.textContent||e.innerHTML||"";Array.from(e.attributes).forEach((e=>t.setAttribute(e.name,e.value))),t.appendChild(document.createTextNode(o)),e.parentNode.replaceChild(t,e)})),GLOBAL_CONFIG.islazyload&&window.lazyLoadInstance.update(),"function"==typeof chatBtnFn&&chatBtnFn(),"function"==typeof panguInit&&panguInit(),"function"==typeof gtag&&gtag("config","",{page_path:window.location.pathname}),"object"==typeof _hmt&&_hmt.push(["_trackPageview",window.location.pathname]),"function"==typeof loadMeting&&document.getElementsByClassName("aplayer").length&&loadMeting(),"object"==typeof Prism&&Prism.highlightAll(),"object"==typeof preloader&&preloader.endLoading()})),document.addEventListener("pjax:error",(e=>{404===e.request.status&&pjax.loadUrl("/404.html")}))</script><script async data-pjax src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script></div><script data-pjax>function butterfly_swiper_injector_config(){var s=document.getElementById("recent-posts");console.log("已挂载butterfly_swiper"),s.insertAdjacentHTML("afterbegin",'<div class="recent-post-item" style="height: auto;width: 100%"><div class="blog-slider swiper-container-fade swiper-container-horizontal" id="swiper_container"><div class="blog-slider__wrp swiper-wrapper" style="transition-duration: 0ms;"><div class="blog-slider__item swiper-slide" style="background:url(https://cdn1.tianli0.top/gh/web-xc/iMG/postss/vue.png);border-radius:12px;opacity: 1; transform: translate3d(0px, 0px, 0px); transition-duration: 0ms;"><div class="blog-slider__content"><span class="blog-slider__code">2023-08-31</span><a class="blog-slider__title" onclick="pjax.loadUrl(&quot;post/ds2s/&quot;);" href="javascript:void(0);" alt="">整个前端面试题</a><div class="blog-slider__text">点击查看</div></div></div><div class="blog-slider__item swiper-slide" style="background:url(https://cdn1.tianli0.top/gh/web-xc/iMG/postss/vue.png);border-radius:12px;opacity: 1; transform: translate3d(0px, 0px, 0px); transition-duration: 0ms;"><div class="blog-slider__content"><span class="blog-slider__code">2023-08-28</span><a class="blog-slider__title" onclick="pjax.loadUrl(&quot;post/ds23/&quot;);" href="javascript:void(0);" alt="">常见前端面试题</a><div class="blog-slider__text">点击查看</div></div></div><div class="blog-slider__item swiper-slide" style="background:url(https://cdn1.tianli0.top/gh/web-xc/iMG/postss/vue.png);border-radius:12px;opacity: 1; transform: translate3d(0px, 0px, 0px); transition-duration: 0ms;"><div class="blog-slider__content"><span class="blog-slider__code">2023-07-26</span><a class="blog-slider__title" onclick="pjax.loadUrl(&quot;post/fe33/&quot;);" href="javascript:void(0);" alt="">硅谷甄选运营平台</a><div class="blog-slider__text">点击查看</div></div></div><div class="blog-slider__item swiper-slide" style="background:url(https://cdn1.tianli0.top/gh/web-xc/iMG/postss/vue.png);border-radius:12px;opacity: 1; transform: translate3d(0px, 0px, 0px); transition-duration: 0ms;"><div class="blog-slider__content"><span class="blog-slider__code">2023-07-17</span><a class="blog-slider__title" onclick="pjax.loadUrl(&quot;post/ew32/&quot;);" href="javascript:void(0);" alt="">Vue第三天</a><div class="blog-slider__text">点击查看</div></div></div><div class="blog-slider__item swiper-slide" style="background:url(https://cdn1.tianli0.top/gh/web-xc/iMG/postss/vue.png);border-radius:12px;opacity: 1; transform: translate3d(0px, 0px, 0px); transition-duration: 0ms;"><div class="blog-slider__content"><span class="blog-slider__code">2023-07-16</span><a class="blog-slider__title" onclick="pjax.loadUrl(&quot;post/aw92/&quot;);" href="javascript:void(0);" alt="">Vue第二天</a><div class="blog-slider__text">点击查看</div></div></div><div class="blog-slider__item swiper-slide" style="background:url(https://cdn1.tianli0.top/gh/web-xc/iMG/postss/vue.png);border-radius:12px;opacity: 1; transform: translate3d(0px, 0px, 0px); transition-duration: 0ms;"><div class="blog-slider__content"><span class="blog-slider__code">2023-07-14</span><a class="blog-slider__title" onclick="pjax.loadUrl(&quot;post/ou67/&quot;);" href="javascript:void(0);" alt="">Vue第一天</a><div class="blog-slider__text">点击查看</div></div></div><div class="blog-slider__item swiper-slide" style="background:url(https://cdn1.tianli0.top/gh/web-xc/iMG/postss/vue.png);border-radius:12px;opacity: 1; transform: translate3d(0px, 0px, 0px); transition-duration: 0ms;"><div class="blog-slider__content"><span class="blog-slider__code">2023-07-05</span><a class="blog-slider__title" onclick="pjax.loadUrl(&quot;post/fn32/&quot;);" href="javascript:void(0);" alt="">Vue框架笔记</a><div class="blog-slider__text">点击查看</div></div></div><div class="blog-slider__item swiper-slide" style="background:url(https://npm.elemecdn.com/webxc/cover/js1.webp);border-radius:12px;opacity: 1; transform: translate3d(0px, 0px, 0px); transition-duration: 0ms;"><div class="blog-slider__content"><span class="blog-slider__code">2023-06-21</span><a class="blog-slider__title" onclick="pjax.loadUrl(&quot;post/fe11/&quot;);" href="javascript:void(0);" alt="">Vue前置JS功底</a><div class="blog-slider__text">点击查看</div></div></div><div class="blog-slider__item swiper-slide" style="background:url(https://cdn1.tianli0.top/gh/web-xc/iMG/postss/promise.webp);border-radius:12px;opacity: 1; transform: translate3d(0px, 0px, 0px); transition-duration: 0ms;"><div class="blog-slider__content"><span class="blog-slider__code">2023-06-11</span><a class="blog-slider__title" onclick="pjax.loadUrl(&quot;post/pr67/&quot;);" href="javascript:void(0);" alt="">ES6-Promise语法与原理</a><div class="blog-slider__text">点击查看</div></div></div><div class="blog-slider__item swiper-slide" style="background:url(https://cdn1.tianli0.top/gh/web-xc/iMG/postss/ajax.webp);border-radius:12px;opacity: 1; transform: translate3d(0px, 0px, 0px); transition-duration: 0ms;"><div class="blog-slider__content"><span class="blog-slider__code">2023-06-08</span><a class="blog-slider__title" onclick="pjax.loadUrl(&quot;post/or01/&quot;);" href="javascript:void(0);" alt="">Ajax第四天</a><div class="blog-slider__text">点击查看</div></div></div><div class="blog-slider__item swiper-slide" style="background:url(https://cdn1.tianli0.top/gh/web-xc/iMG/postss/ajax.webp);border-radius:12px;opacity: 1; transform: translate3d(0px, 0px, 0px); transition-duration: 0ms;"><div class="blog-slider__content"><span class="blog-slider__code">2023-06-07</span><a class="blog-slider__title" onclick="pjax.loadUrl(&quot;post/fs67/&quot;);" href="javascript:void(0);" alt="">Ajax第三天</a><div class="blog-slider__text">点击查看</div></div></div><div class="blog-slider__item swiper-slide" style="background:url(https://npm.elemecdn.com/webxc/cover/js1.webp);border-radius:12px;opacity: 1; transform: translate3d(0px, 0px, 0px); transition-duration: 0ms;"><div class="blog-slider__content"><span class="blog-slider__code">2023-05-11</span><a class="blog-slider__title" onclick="pjax.loadUrl(&quot;post/fe66/&quot;);" href="javascript:void(0);" alt="">JS进阶第四天</a><div class="blog-slider__text">点击查看</div></div></div><div class="blog-slider__item swiper-slide" style="background:url(https://npm.elemecdn.com/webxc/cover/js1.webp);border-radius:12px;opacity: 1; transform: translate3d(0px, 0px, 0px); transition-duration: 0ms;"><div class="blog-slider__content"><span class="blog-slider__code">2023-05-10</span><a class="blog-slider__title" onclick="pjax.loadUrl(&quot;post/fe99/&quot;);" href="javascript:void(0);" alt="">JS进阶第三天</a><div class="blog-slider__text">点击查看</div></div></div><div class="blog-slider__item swiper-slide" style="background:url(https://npm.elemecdn.com/webxc/cover/js1.webp);border-radius:12px;opacity: 1; transform: translate3d(0px, 0px, 0px); transition-duration: 0ms;"><div class="blog-slider__content"><span class="blog-slider__code">2023-05-05</span><a class="blog-slider__title" onclick="pjax.loadUrl(&quot;post/us87/&quot;);" href="javascript:void(0);" alt="">JS进阶第二天</a><div class="blog-slider__text">点击查看</div></div></div><div class="blog-slider__item swiper-slide" style="background:url(https://npm.elemecdn.com/webxc@1.0.12/cover/cover15.jpg);border-radius:12px;opacity: 1; transform: translate3d(0px, 0px, 0px); transition-duration: 0ms;"><div class="blog-slider__content"><span class="blog-slider__code">2022-10-31</span><a class="blog-slider__title" onclick="pjax.loadUrl(&quot;post/2db5/&quot;);" href="javascript:void(0);" alt="">移动开发-Flex布局</a><div class="blog-slider__text">点击查看</div></div></div><div class="blog-slider__item swiper-slide" style="background:url(https://npm.elemecdn.com/webxc@1.0.12/cover/cover16.jpg);border-radius:12px;opacity: 1; transform: translate3d(0px, 0px, 0px); transition-duration: 0ms;"><div class="blog-slider__content"><span class="blog-slider__code">2022-11-14</span><a class="blog-slider__title" onclick="pjax.loadUrl(&quot;post/1c7e/&quot;);" href="javascript:void(0);" alt="">移动开发-媒体查询</a><div class="blog-slider__text">点击查看</div></div></div><div class="blog-slider__item swiper-slide" style="background:url(https://npm.elemecdn.com/webxc@1.0.12/cover/cover17.jpg);border-radius:12px;opacity: 1; transform: translate3d(0px, 0px, 0px); transition-duration: 0ms;"><div class="blog-slider__content"><span class="blog-slider__code">2022-11-17</span><a class="blog-slider__title" onclick="pjax.loadUrl(&quot;post/7fc/&quot;);" href="javascript:void(0);" alt="">移动开发-响应式</a><div class="blog-slider__text">点击查看</div></div></div></div><div class="blog-slider__pagination swiper-pagination-clickable swiper-pagination-bullets"></div><div class="swiper-button-prev"></div><div class="swiper-button-next"></div></div></div>')}for(var elist="null".split(","),cpage=location.pathname,epage="all",flag=0,i=0;i<elist.length;i++)cpage.includes(elist[i])&&flag++;("all"===epage&&0==flag||epage===cpage)&&butterfly_swiper_injector_config()</script><script defer src="https://npm.elemecdn.com/webxc@1.0.12/css/swiper/swiper.min.js"></script><script defer data-pjax src="https://npm.elemecdn.com/webxc@1.0.12/css/swiper/swiper_init.js"></script></body></html>